package com.butang.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

/**
 * ClassName: JwtUtils
 * Package: com.butang.utils
 * Description:
 *
 * @Author BuTang
 * @Create 2023/7/17 13:58
 * @Version 1.0
 */
public class JwtUtils {
    //private static final String singleKey = "butang";
    private static long expire = 43200000L;

    public static String generateJwt(Map<String, Object> claims) {
        String jwt = Jwts.builder()
                .setClaims(claims)
                //.signWith(SignatureAlgorithm.ES256, singleKey)
                .signWith(SignatureAlgorithm.HS256, "butang")
                .setExpiration((new Date(System.currentTimeMillis() + expire)))
                .compact();
        return jwt;
    }

    public static Claims parseJwt(String jwts) {
        Claims claims = Jwts.parser()
                .setSigningKey("butang")
                .parseClaimsJws(jwts)
                .getBody();
        return claims;
    }
}
